<?php

if (! defined('LIB_PATH'))
{
    die('The file ' . __FILE__ . ' needs to be required from the main executable of PhpPhoenix');
}

/**
 * This class is inheriting the Base class
 *
 * @see Base
 */
require_once LIB_PATH . 'Base.php';

/**
 * CommandLineScript 
 * 
 * @uses Base
 * @abstract
 * @package phoenix-php
 * @subpackage scripts
 * @version $id$
 * @author Pablo López Torres <pablolopeztorres@gmail.com
 */
abstract class CommandLineScript extends Base
{
    /**
     * main
     * 
     * This is not planned to be used as anything but the main standard caller 
     * 
     * @param mixed $argc 
     * @param mixed $argv 
     * @static
     * @abstract
     * @author Pablo López Torres <pablolopeztorres@gmail.com>
     * @access public
     * @return void
     */
    // abstract public static function main($argc, $argv);

    /**
     * getHelp
     * 
     * Return a string with the help provided to the user
     * when the config flag --help or -h is provided
     * 
     * @static
     * @abstract
     * @author Pablo López Torres <pablolopeztorres@gmail.com>
     * @access public
     * @param string Error message to be shown (default : "")
     * @return string
     * @todo pablo - implement me
     */
    // abstract public static function getHelp($errorMessage = "");

    /**
     * getColor
     * 
     * If is color enabled, it returns the escape sequence that allows the
     * command line client to display a color. It will also allow to display
     * effects like underlines and bolds.
     * 
     * In case of any error like an incorrect value or not color enabled,
     * an empty string will be returned.
     * 
     * @param mixed $color 
     * @static
     * @author Pablo López Torres <pablolopeztorres@gmail.com>
     * @access public
     * @return string
     */
    public static function getColor($color)
    {
        $escapeSequence = '';
        // if color is enabled and the color is recognized
        if (self::isColorEnabled() && isset(self::$colors[$color]))
        {
            // set it and return it
            $escapeSequence = "\033[" . implode(';', self::$colors[$color]) . "m";
        }
        return $escapeSequence;
    }

    /**
     * isColorEnabled
     * 
     * This function returns a boolean if the command line client can display
     * colors
     * 
     * @static
     * @author Pablo López Torres <pablolopeztorres@gmail.com>
     * @access public
     * @return boolean
     */
    public static function isColorEnabled()
    {
        return TRUE;
    }

    /**
     * colors 
     * 
     * Colors to be used in the output of the debug file (when STDIN)
     *
     * They will be stored as an array with one or two elements.
     *
     *  - If only one (for example A), the escape sequence will be 
     *    formed as \033[Am 
     *  - If two are provided (A, B) the escape sequence will be 
     *    formed as \033[A;Bm
     *
     * @var array
     */
    private static $colors = array(
        'normal' => array(0),
        'bold' => array(1),
        'underscore' => array(4),
        'reverse' => array(7),

        'light_gray' => array(1,30),
        'light_red' => array(1,31),
        'light_green' => array(1,32),
        'light_brown' => array(1,33),
        'light_blue' => array(1,34),
        'light_purple' => array(1,35),
        'light_cyan' => array(1,36),
        'light_white' => array(1,37),

        'gray' => array(0,30),
        'red' => array(0,31),
        'green' => array(0,32),
        'brown' => array(0,33),
        'blue' => array(0,34),
        'purple' => array(0,35),
        'cyan' => array(0,36),
        'white' => array(0,37),
    );
}
